//package com.aaa.pay.service.impl;
//
//import com.aaa.entity.Shop;
//import com.aaa.pay.VO.PayInfoVO;
//import com.aaa.pay.service.PayService;
//import com.alipay.api.AlipayApiException;
//import com.alipay.api.AlipayClient;
//import com.alipay.api.DefaultAlipayClient;
//import com.alipay.api.request.AlipayTradePrecreateRequest;
//import com.alipay.api.response.AlipayTradePrecreateResponse;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.PostConstruct;
//import java.math.RoundingMode;
//
///**
// * @Author 崔灿
// * @Date 2023/03/06 16:04
// * @ClassName PayServiceImpl
// * @Description
// * @Version 1.0
// */
//
//
//@Service("PayServiceImpl")
//@Slf4j
//public class PayServiceImpl implements PayService {
//
//    @Autowired
//    private OrderMapper orderMapper;
//    @Autowired
//    private ShopMapper shopMapper;
//
//    @Value("${alipay.app-id}")
//    private String appId;
//
//    @Value("${alipay.private-key}")
//    private String privateKey;
//
//    @Value("${alipay.public-key}")
//    private String publicKey;
//
//    @Value("${alipay.gateway}")
//    private String gateway;
//
//    private AlipayClient alipayClient;
//
//    @PostConstruct
//    public void init() {
//        alipayClient = new DefaultAlipayClient(gateway,
//                appId, privateKey, "json", "utf-8", publicKey, "RSA2");
//    }
//
//    @Override
//    public PayInfoVO getPayInfo(String orderId) {
//        log.info("info ============= {}",orderId);
//        // 根据订单id得到订单详情
//        Order order = orderMapper.selectById(orderId);
//        String sellId = order.getSellId();
//        // 根据商家ID获取商家信息
//        Shop shop = shopMapper.selectById(sellId);
//        String shopSellName = shop.getSellName();
//        AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
//        // 支付请求
//        request.setBizContent("{" +
//                "    \"out_trade_no\":\"" + orderId + "\"," +//商户订单号
//                "    \"total_amount\":\"" + order.getOrderPrice().setScale(2, RoundingMode.CEILING) + "\"," +
//                "    \"subject\":\"" + shopSellName + "当面付" + "\"," +
//                "    \"store_id\":\"00100\"," + // (必填) 商户门店编号，通过门店号和商家后台可以配置精准到门店的折扣信息，详询支付宝技术支持
//                "    \"timeout_express\":\"5m\"}");//订单允许的最晚付款时间
//        AlipayTradePrecreateResponse response = null;
//        //支付宝二维码URL
//        String qrCode = "";
//        try {
//            response = alipayClient.execute(request);
//            if (!response.isSuccess()) {
//                throw new CustomException("生成支付宝订单失败:" + response.getMsg());
//            }
//            qrCode = response.getQrCode();
//        } catch (AlipayApiException e) {
//            throw new CustomException(e.getMessage());
//        }
//        // 封装支付信息 返回
//        PayInfoVO payInfoVO = new PayInfoVO();
//        payInfoVO.setOrderId(order.getOrderId());
//        payInfoVO.setShopName(shopSellName);
//        payInfoVO.setUrl(qrCode);
//        log.info("payInfo: {}",payInfoVO);
//        return payInfoVO;
//    }
//}
